import Vue from 'vue'
import VeeValidate,{Validator} from 'vee-validate';
Vue.use(VeeValidate);
//使用中文提示
import cn from 'vee-validate/dist/locale/zh_CN';
Validator.localize('cn', cn);
const dict = {
  cn: {messages: {required: (name) => `${name}不能为空!`}}  // name接受alias的值.
}
Validator.localize(dict);

Validator.extend('phone', {
    getMessage: field => "请输入正确的手机号码",
    validate: value => value.length === 11 && /^((13|14|15|17|18)[0-9]{1}\d{8})$/.test(value)
});
// ^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&*]+$)[a-zA-Z\d!@#$%^&*]+$
Validator.extend('password', {
  getMessage: field => "密码格式为6位 字母+数字，字母+特殊字符，数字+特殊字符",
  validate: value => value.length >= 6 && /^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&*]+$)[a-zA-Z\d!@#$%^&*]+$/.test(value)
});

Validator.extend('age', {
  getMessage: field => "年龄只能输入15到50",
  validate: value => value<=50 && value>=15
});
Validator.extend('credit', {
  getMessage: field => "只能输入0到100之间整数",
  validate: value => value<=100 && value>=0
});
export default Validator;